//
//  SK_MASConstraintMaker.h
//  SK_Masonry
//
//  Created by Jonas Budelmann on 20/07/13.
//  Copyright (c) 2013 cloudling. All rights reserved.
//

#import "SK_MASConstraint.h"
#import "SK_MASUtilities.h"

typedef NS_OPTIONS(NSInteger, SK_MASAttribute) {
    SK_MASAttributeLeft = 1 << NSLayoutAttributeLeft,
    SK_MASAttributeRight = 1 << NSLayoutAttributeRight,
    SK_MASAttributeTop = 1 << NSLayoutAttributeTop,
    SK_MASAttributeBottom = 1 << NSLayoutAttributeBottom,
    SK_MASAttributeLeading = 1 << NSLayoutAttributeLeading,
    SK_MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
    SK_MASAttributeWidth = 1 << NSLayoutAttributeWidth,
    SK_MASAttributeHeight = 1 << NSLayoutAttributeHeight,
    SK_MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
    SK_MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
    SK_MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
    
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
    
    SK_MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline,
    SK_MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline,
    
#endif
    
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
    
    SK_MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
    SK_MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
    SK_MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
    SK_MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
    SK_MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
    SK_MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
    SK_MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
    SK_MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,

#endif
    
};

/**
 *  Provides factory methods for creating SK_MASConstraints.
 *  Constraints are collected until they are ready to be installed
 *
 */
@interface SK_MASConstraintMaker : NSObject

/**
 *	The following properties return a new SK_MASViewConstraint
 *  with the first item set to the makers associated view and the appropriate SK_MASViewAttribute
 */
@property (nonatomic, strong, readonly) SK_MASConstraint *left;
@property (nonatomic, strong, readonly) SK_MASConstraint *top;
@property (nonatomic, strong, readonly) SK_MASConstraint *right;
@property (nonatomic, strong, readonly) SK_MASConstraint *bottom;
@property (nonatomic, strong, readonly) SK_MASConstraint *leading;
@property (nonatomic, strong, readonly) SK_MASConstraint *trailing;
@property (nonatomic, strong, readonly) SK_MASConstraint *width;
@property (nonatomic, strong, readonly) SK_MASConstraint *height;
@property (nonatomic, strong, readonly) SK_MASConstraint *centerX;
@property (nonatomic, strong, readonly) SK_MASConstraint *centerY;
@property (nonatomic, strong, readonly) SK_MASConstraint *baseline;

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)

@property (nonatomic, strong, readonly) SK_MASConstraint *firstBaseline;
@property (nonatomic, strong, readonly) SK_MASConstraint *lastBaseline;

#endif

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)

@property (nonatomic, strong, readonly) SK_MASConstraint *leftMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *rightMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *topMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *bottomMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *leadingMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *trailingMargin;
@property (nonatomic, strong, readonly) SK_MASConstraint *centerXWithinMargins;
@property (nonatomic, strong, readonly) SK_MASConstraint *centerYWithinMargins;

#endif

/**
 *  Returns a block which creates a new SK_MASCompositeConstraint with the first item set
 *  to the makers associated view and children corresponding to the set bits in the
 *  SK_MASAttribute parameter. Combine multiple attributes via binary-or.
 */
@property (nonatomic, strong, readonly) SK_MASConstraint *(^attributes)(SK_MASAttribute attrs);

/**
 *	Creates a SK_MASCompositeConstraint with type SK_MASCompositeConstraintTypeEdges
 *  which generates the appropriate SK_MASViewConstraint children (top, left, bottom, right)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) SK_MASConstraint *edges;

/**
 *	Creates a SK_MASCompositeConstraint with type SK_MASCompositeConstraintTypeSize
 *  which generates the appropriate SK_MASViewConstraint children (width, height)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) SK_MASConstraint *size;

/**
 *	Creates a SK_MASCompositeConstraint with type SK_MASCompositeConstraintTypeCenter
 *  which generates the appropriate SK_MASViewConstraint children (centerX, centerY)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) SK_MASConstraint *center;

/**
 *  Whether or not to check for an existing constraint instead of adding constraint
 */
@property (nonatomic, assign) BOOL updateExisting;

/**
 *  Whether or not to remove existing constraints prior to installing
 */
@property (nonatomic, assign) BOOL removeExisting;

/**
 *	initialises the maker with a default view
 *
 *	@param	view	any SK_MASConstraint are created with this view as the first item
 *
 *	@return	a new SK_MASConstraintMaker
 */
- (id)initWithView:(SK_MAS_VIEW *)view;

/**
 *	Calls install method on any SK_MASConstraints which have been created by this maker
 *
 *	@return	an array of all the installed SK_MASConstraints
 */
- (NSArray *)install;

- (SK_MASConstraint * (^)(dispatch_block_t))group;

@end
